import axios from '@/libs/axios1'
import { responesAssemble, requestAssemble } from '@/libs/utils'
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' }
let formHeaders = { 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' }

/**********团队得失分情况*********/
//导出积分列表(知识赛积分页面)
export const outputExport = params => {
  params = requestAssemble(params)
  return new Promise(resolve => {
    axios({
      url: `/compete/integral/${params.sceneId}/${params.contestName}/${params.matchMode}/${params.contestType}`,
      method: 'get',
      responseType:'blob',
      headers: jsonHeaders
    }).then(res => {
      resolve(res)
    })
  });
}


//设计师查看操作员竞赛和演练
export const getExpCompeteList= params => {
  return axios({
    url: `/compete/contest/student/allTypeContestPage`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}



//新红蓝对抗保存加减分记录
export const addScoreRecord = data => {
  return axios({
    url: `/compete/ctfTeamBasic/addOrSub`,
    method: 'post',
    data:data,
    headers: jsonHeaders
  })
}
//分页查询个人积分列表(知识赛积分)
export const listUserCtfIntegral = (id,matchMode,params) => {
  matchMode = '1' // 接口变了，这个参数的意思变为个人还是团队赛，应该改为1
  params = requestAssemble(params)
  return new Promise(resolve => {
    axios({
      url: `/compete/integral/${id}/${matchMode}`,
      method: 'get',
      params:params,
      headers: jsonHeaders
    }).then(res => {
      resolve(responesAssemble(res, params))
    })
  });
}

//撤销积分计算(知识赛积分)
export const cancelIntegralCom = (sceneId) => {
  return new Promise(resolve => {
    axios({
      url: `/compete/integral/${sceneId}`,
      method: 'post',
      headers: jsonHeaders
    }).then(res => {
      resolve(responesAssemble(res))
    })
  });
}

//积分计算(知识赛积分)
export const integralCom = (sceneId,matchMode) => {
  return new Promise(resolve => {
    axios({
      url: `/compete/integral/${sceneId}`,
      method: 'post',
      headers: jsonHeaders
    }).then(res => {
      resolve(responesAssemble(res))
    })
  });
}

/*********排名统计情况*********/
//查询队伍得失分记录
export const teamScoreStatis= params => {
  return axios({
    url: `/compete/teamScoreRecord/page`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

/**
 * 攻防赛plus获取队伍防守得分记录
 * @param {*} params 
 * @returns 
 */
export const getAwdPlusScore= params => {
  return axios({
    url: `/compete/teamScoreRecord/AWDPlus/defense/page`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取对抗演练势力方排名
export const teamScoreRank= (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/drill/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//对抗演练团队排名
export const teamRankStatic = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/drillTeam/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取排名统计列表分页(攻防赛)
export const adcTeamRankStatic = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取排名统计列表分页(攻防赛plus)
export const awdPlusTeamRankStatic = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/awdPlus/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

export const opTeamRankStatic = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/OM/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取渗透排行
export const stTeamRankStatis = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/permeate/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//提交记录
export const submitRecord = (params) => {
  return axios({
    url: `/compete/userSubmitRecord/page`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

/**
 * 获取夺旗赛的团队排名
 * @param {*} params 
 * @returns 
 */
export const getCtfAddressDetails = params => {
  return axios({
    url: `/compete/userSubmitRecord/ctf/page`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}


//获取护网攻击方团队排行
export const hwTeamRankStatis = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/protect/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

// 获取护网防守方目标排名
export const hwDefenseTeamRankStatis = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/protect/defense/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//提交报告统计
export const reportStatis = (params) => {
  return axios({
    url: `/referee/designer/report`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//积分计算
export const integralCalc = sceneId => {
  return axios({
    url: `/compete/integral/${sceneId}`,
    method: 'post',
    headers: jsonHeaders
  })
}

//获取积分列表(团队积分和个人积分)
export const getIntegralList = (sceneId,type,params) => {
  return axios({
    url: `/compete/integral/${sceneId}/${type}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取ctf团队排行
export const ctfTeamRankStatis = (sceneId,params) => {
  return axios({
    url: `/compete/teamScoreRecord/ctf/page/${sceneId}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//获取攻防赛所有团队的总攻击得分,总防守失分,总异常得分,总异常失分
export const adcTeamScoreRecordTotal = sceneId => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/${sceneId}/awdTotal`,
    method: 'get',
    params:{},
    headers: jsonHeaders
  })
}

// 查询攻防赛plus所有团队的总攻击得分,总防守得分,总重置失分,总异常失分
export const awdPlusTeamScoreRecordTotal = sceneId => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/${sceneId}/awdPlusTotal`,
    method: 'get',
    params:{},
    headers: jsonHeaders
  })
}

export const opTeamScoreRecordTotal = sceneId => {
  return axios({
    url: `/compete/teamScoreRecord/statistics/${sceneId}/OMTotal`,
    method: 'get',
    params:{},
    headers: jsonHeaders
  })
}

//保存加减分记录
export const saveScoreRecord = data => {
  return axios({
    url: `/compete/teamScoreRecord`,
    method: 'post',
    data:data,
    headers: jsonHeaders
  })
}

/**
 * 查询是否有报告存在
 * @param sceneId 指定竞赛、演练ID
 * @returns {*}
 */
 export const hasReport = (sceneId) => {
  return axios({
    url: `/compete/ctfReport/checkCount/${sceneId}`,
    method: 'get',
    headers: jsonHeaders
  })
}

/**
 * 查询指定场景下的结题报告列表
 * @param sceneId 指定竞赛、演练ID
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param teamName 团队名
 * @param fileName 报告名称
 * @param questionName 指定关联的题目名称
 * 
 * @returns {*}
 */
 export const getReportList = (sceneId,params) => {
  return axios({
    url: `/compete/ctfReport/page/${sceneId}`,
    method: 'get',
    headers: jsonHeaders,
    params: params
  })
}

//打包下载所有报告
export const downloadSceneAllReport = (sceneId,ids,fn) => {
  return axios({
    url: `/compete/ctfReport/${sceneId}/downloadZip`,
    method: 'post',
    data:ids,
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
    onDownloadProgress: fn,
    timeout:0
  })
}

//夺旗赛提交统计下载报告
export const downloadSubmitAllReport = (sceneId,teamName,ids, fn) => {
  return axios({
    url: `/compete/ctfReport/download/${sceneId}/${teamName}`,
    method: 'post',
    data:ids,
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
    onDownloadProgress: fn,
    timeout:0
  })
}

//夺旗赛更具题目下载报告
export const downloadQuestionAllReport = (sceneId,questionId,params, fn) => {
  return axios({
    url: `/compete/ctfReport/downloadQuestion/${sceneId}/${questionId}`,
    method: 'post',
    params,
    headers:{
        'Content-Type': 'application/json; application/octet-stream'
    },
    responseType: 'blob',
    onDownloadProgress: fn,
    timeout:0
  })
}
//下载文件
export const downloadFile = id  => {
  return axios({
    url: `/minio/download/${id}`,
    method: 'get',
    params:{},
    headers:{
        'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    },
    responseType: 'blob',
    timeout:0
  })
}

export const uploadFiles = data => {
  return axios({
    url: `/minio/upload/permanent?visibility=company&type=images&bucket=tmpl-img`,
    method: 'POST',
    headers: formHeaders,
    data
  })
}

//红蓝对抗得失分次数列表
export const awdDrillScoreDetail = (sceneId,scoreType,params) => {
  return axios({
    url: `/compete/teamScoreRecord/detail/${sceneId}/${scoreType}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

//攻防赛得失分记录统计
export const adcTeamScoreStatis = (sceneId,scoreType,params) => {
  return axios({
    url: `/compete/teamScoreRecord/detailAWD/${sceneId}/${scoreType}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}

/**
 * 获取夺旗赛题目解答详情
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param sceneId 指定场景ID
 * @param questionName 搜索条件，题目名称
 * @returns {*}
 */
export const getQuestionSolveList = ({ pageIndex, pageSize, sceneId, questionName }) => {
  return axios({
    url: `/compete/teamScoreRecord/getCtfT/${sceneId}`,
    method: 'get',
    params: {
      pageIndex,
      pageSize,
      sceneId,
      questionName
    },
    headers: jsonHeaders
  })
}


/**
 * 获取夺旗赛题目解答详情
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param sceneId 指定场景ID
 * @param questionId 指定题目ID
 * @param finishStatus 是否完成（1：完成 0：未完成）
 * @param teamName 搜索条件，团队名称
 * @returns {*}
 */
export const getQuestionSolveStatic = ({ pageIndex, pageSize, sceneId, questionId, finishStatus, teamName }) => {
  return axios({
    url: `/compete/teamScoreRecord/detailCtfT/${sceneId}/${questionId}/${finishStatus}`,
    method: 'get',
    params: {
      pageIndex,
      pageSize,
      sceneId,
      questionId,
      finishStatus,
      teamName
    },
    headers: jsonHeaders
  })
}

/**
 * 获取团队题目完成情况列表
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param sceneId 指定场景ID
 * @param teamName 团队名称
 * @param teamId 团队ID
 * @returns {*}
 */
export const getTeamSolveList = ({ pageIndex, pageSize, sceneId, teamName, teamId }) => {
  return axios({
    url: `/compete/teamScoreRecord/ctf/page/${sceneId}`,
    method: 'get',
    params: {
      pageIndex,
      pageSize,
      sceneId,
      teamName,
      teamId
    },
    headers: jsonHeaders
  })
}

/**
 * 获取团队题目完成详情
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param sceneId 指定场景ID
 * @param teamId 指定团队ID
 * @param finishStatus 是否完成（1：完成 0：未完成）
 * @param questionName 搜索条件，题目名称
 * @returns {*}
 */
export const getTeamSolveStatic = ({ pageIndex, pageSize, sceneId, teamId, finishStatus, questionName }) => {
  return axios({
    url: `/compete/teamScoreRecord/detailCtfQ/${sceneId}/${teamId}/${finishStatus}`,
    method: 'get',
    params: {
      pageIndex,
      pageSize,
      sceneId,
      teamId,
      finishStatus,
      questionName
    },
    headers: jsonHeaders
  })
}

/**
 * 获取大组排名
 * @param pageIndex 当前页
 * @param pageSize 分页大小
 * @param sceneId 指定场景ID
 * @param name 大组名称
 * @returns {*}
 */
export const getSuperTeamRank = ({ pageIndex, pageSize, sceneId, teamName }) => {
  return axios({
    url: `/compete/teamScoreRecord/ctf/super/${sceneId}`,
    method: 'get',
    params: {
      pageIndex,
      pageSize,
      sceneId,
      teamName
    },
    headers: jsonHeaders
  })
}

/**
 * 查询该题目被扣分的团队
 * @param sceneId 指定比赛
 * @param teamId 指定答题团队
 * @param targetId 指定题目
 * @returns {*}
 */
 export const getPenalizedTeam = ({sceneId, teamId, targetId}) => {
  return axios({
      url: `/compete/teamScoreRecord/getSub/${sceneId}/${teamId}/${targetId}`,
      method: 'get',
      headers: jsonHeaders
  })
}

// 对抗手动加分
 export const teamScoreRecordAddDk = (data,projectId,sceneId) => {
  return axios({
      url: `/compete/teamScoreRecord/addDk/${projectId}/${sceneId}`,
      method: 'post',
      data,
      headers: jsonHeaders
  })
}
// 对抗手动减分
export const teamScoreRecordSubDk = (data,params) => {
  let {projectId,sceneId,teamId,score} = data
  return axios({
      url: `/compete/teamScoreRecord/subDk/${projectId}/${sceneId}/${teamId}/${score}`,
      method: 'post',
      params,
      headers: jsonHeaders
  })
}

// 对抗加减分列表
export const getSubAddListDkList = (params) => {
  return axios({
      url: `/compete/teamScoreRecord/getSubAddListDk`,
      method: 'get',
      params,
      headers: jsonHeaders
  })
}